/*    */ package com.newcrm.db;
/*    */ 
/*    */ import com.newcrm.exception.DBException;
/*    */ import java.sql.Connection;
/*    */ import java.sql.SQLException;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ import org.apache.commons.dbutils.DbUtils;
/*    */ import org.apache.commons.dbutils.GenKeyQueryRunner;
/*    */ import org.apache.commons.dbutils.MyMapListHandler;
/*    */ import org.apache.commons.dbutils.QueryRunner;
/*    */ import org.apache.commons.dbutils.handlers.ScalarHandler;
/*    */ import org.apache.log4j.Logger;
/*    */ 
/*    */ public class ImportManager
/*    */ {
/* 20 */   private static Logger logger = Logger.getLogger(ImportManager.class
/* 21 */     .getName());
/*    */ 
/*    */   public int add(String type, String fileName, int companyId, String userId)
/*    */     throws DBException, SQLException
/*    */   {
/* 36 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 37 */     if (conn == null) {
/* 38 */       throw new DBException();
/*    */     }
/* 40 */     GenKeyQueryRunner runner = new GenKeyQueryRunner(
/* 41 */       new ScalarHandler(), new String[] { "ImportId" });
/*    */     try {
/* 43 */       runner.update(conn, "INSERT INTO T_Import_Info (ImportType, FileName, CompanyId, CreateDate, CreateUserId) values (?, ?, ?, NOW(), ?)", new Object[] { type, fileName, 
/* 44 */         Integer.valueOf(companyId), userId });
/* 45 */       return ((Long)runner.getGeneratedKeys()).intValue();
/*    */     } finally {
/*    */       try {
/* 48 */         DbUtils.close(conn);
/*    */       } catch (SQLException e) {
/* 50 */         logger.warn("close conn failed", e);
/*    */       }
/*    */     }
/*    */   }
/*    */ 
/*    */   public List<Map<String, Object>> getTop5Customer(int importId)
/*    */     throws DBException, SQLException
/*    */   {
/* 65 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 66 */     if (conn == null) {
/* 67 */       throw new DBException();
/*    */     }
/*    */ 
/* 70 */     QueryRunner runner = new QueryRunner();
/*    */     try {
/* 72 */       return (List)runner.query(conn, "SELECT A.CustomerId, A.Name, A.ParentCustomerId, B.Name AS ParentCustomerName FROM T_Customer_Info AS A INNER JOIN T_Customer_Info AS B ON A.ParentCustomerId = B.CustomerId WHERE A.Type = ? AND A.ImportId = ? LIMIT 0, 5", 
/* 73 */         new MyMapListHandler(), new Object[] { Integer.valueOf(1), Integer.valueOf(importId) });
/*    */     } finally {
/*    */       try {
/* 76 */         DbUtils.close(conn);
/*    */       } catch (SQLException e) {
/* 78 */         logger.warn("close conn failed", e);
/*    */       }
/*    */     }
/*    */   }
/*    */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.db.ImportManager
 * JD-Core Version:    0.6.1
 */